﻿using BigEgg.Framework.Foundation;
using FMStudio.Documents.TemplateDocument.Properties;
using System;
using System.ComponentModel.DataAnnotations;
using System.Xml.Serialization;

namespace FMStudio.Documents.TemplateDocument.Models
{
    public class ProjectItem : Item
    {
        #region Fields
        private string name;
        private string targetFileName;
        private bool replaceParameters;
        #endregion


        public ProjectItem(string name)
        {
            if (name == null) { throw new ArgumentNullException("name"); }

            this.name = name;
            this.targetFileName = name;
            this.replaceParameters = false;
        }

        public ProjectItem()
            : this(string.Empty)
        {
        }


        #region Properties
        /// <summary>
        /// Gets or sets the name of the project item.
        /// </summary>
        [XmlText()]
        [Required(ErrorMessageResourceName = "ProjectItemNameMandatory", ErrorMessageResourceType = typeof(Resources))]
        public string Name
        {
            get { return this.name; }
            set
            {
                if (this.name != value)
                {
                    this.name = value;
                    RaisePropertyChanged("Name");
                }
            }
        }

        /// <summary>
        /// Gets or sets the name of the target item.
        /// </summary>
        [XmlAttribute()]
        [Required(ErrorMessageResourceName = "ProjectItemTargetFileNameMandatory", ErrorMessageResourceType = typeof(Resources))]
        public string TargetFileName
        {
            get { return this.targetFileName; }
            set
            {
                if (this.targetFileName != value)
                {
                    this.targetFileName = value;
                    RaisePropertyChanged("TargetFileName");
                }
            }
        }

        /// <summary>
        /// The items contains in the folder.
        /// </summary>
        [XmlAttribute()]
        public bool ReplaceParameters
        {
            get { return this.replaceParameters; }
            set
            {
                if (this.replaceParameters != value)
                {
                    this.replaceParameters = value;
                    RaisePropertyChanged("ReplaceParameters");
                }
            }
        }
        #endregion
    }
}
